const { defineConfig } = require("@vue/cli-service");
module.exports = defineConfig({
  transpileDependencies: true,
  lintOnSave: false,
  css: {
    loaderOptions: {
      sass: {
        // 全局引入变量和 mixin
        additionalData: `
          @import "@/assets/scss/variable.scss";
          @import "@/assets/scss/mixin.scss";
        `,
      },
    },
  },
  devServer: {
    proxy: {
      "/api": {
        target: "https://autumnfish.cn/",
        changeOrigin: true,
        pathRewrite: {
          "^/api": "",
        },
      },
    },
  },
  // configureWebpack: (config) => {
  //   if (process.env.npm_config_report) {
  //     const BundleAnalyzerPlugin =
  //       require("webpack-bundle-analyzer").BundleAnalyzerPlugin;
  //     config.plugins.push(new BundleAnalyzerPlugin());
  //   }
  // },
  chainWebpack: (config) => {
    // // 发布模式
    config.when(process.env.NODE_ENV === "production", (config) => {
      config
        .plugin("webpack-bundle-analyzer")
        .use(require("webpack-bundle-analyzer").BundleAnalyzerPlugin);
      config.entry("app").clear().add("./src/main.js");
      config.set("externals", {
        pinyin: "pinyin",
      });
      config.plugin("html").tap((args) => {
        args[0].isProd = true;
        return args;
      });
      //去掉代码混淆
      config.optimization.minimize(false);
    });
    //开发模式
    // config.when(process.env.NODE_ENV === "development", (config) => {
    //   config.entry("app").clear().add("./src/main.js");
    //   //cdn
    //   config.set("externals", {
    //     pinyin: "pinyin",
    //   });
    //   //判断是生产模式还是开发模式
    //   config.plugin("html").tap((args) => {
    //     args[0].isProd = true;
    //     return args;
    //   });
    //   //去掉代码混淆
    //   config.optimization.minimize(false);
    // });
  },
  productionSourceMap: false,
  // publicPath: process.env.NODE_ENV === "production" ? "/music-next/" : "/",
});
